﻿using System;
using System.Collections.Generic;
using System.Text;
using Widgetsphere.Generator.Models;
using Widgetsphere.Generator.ProjectItemGenerators;
using Widgetsphere.Generator.DataTransfer;


namespace Acme.GeneratorExtension.GenerateToDataTransfer
{
	/// <summary>
	/// This template will generate the content for the [EntityName]MetaData.cs file. This file
	/// will contain a public partial class [EntityName]MetaData. This file is 
	/// provided as a way to allow programmers to extend the generated class. 
	/// It will be generated once and never over written after that point.
	/// </summary>
	public class MetadataInfoClassExtensionTemplate : BaseDataTransferTemplate
	{
		#region Class Members
		private StringBuilder sb = new StringBuilder();
		private Table _currentTable;
		#endregion

		#region Constructors
		public MetadataInfoClassExtensionTemplate(ModelRoot model, Table currentTable)
		{
			_model = model;
			_currentTable = currentTable;
		}
		#endregion

		#region BaseClassTemplate overrides
		/// <summary>
		/// Returns the generated contents of the file as a string
		/// </summary>
		public override string FileContent
		{
			get
			{
				GenerateContent();
				return sb.ToString();
			}
		}

		/// <summary>
		/// Returns the name of the file. That will be added to the project if it does not exist
		/// </summary>
		public override string FileName
		{
			get { return string.Format("{0}MetaData.cs", _currentTable.PascalName); }
		}
		#endregion

		#region GenerateContent
		private void GenerateContent()
		{
			try
			{
				this.AppendUsingStatements();
				sb.AppendLine("namespace " + DefaultNamespace + ".MetaData");
				sb.AppendLine("{");
				this.AppendClass();
				sb.AppendLine("}");
			}
			catch (Exception ex)
			{
				throw;
			}
		}

		#endregion

		#region namespace / objects

		public void AppendUsingStatements()
		{
			sb.AppendLine("using System;");
			sb.AppendLine();
		}

		public void AppendClass()
		{
			sb.AppendLine("	public partial class " + _currentTable.PascalName + "MetaData");
			sb.AppendLine("	{");
			sb.AppendLine("	}");
			sb.AppendLine();
		}

		#endregion

	}
}